package com.iprojectmanager.views;


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.iprojectmanager.managers.*;
import com.iprojectmanager.entities.*;
import java.util.ArrayList;

/**
 *
 * @author JKA
 */
public class VistaEliminarProyecto extends Vista {

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        mainView(response.getWriter());
    } 

    public void mainView(PrintWriter out,HttpServletRequest request)
    {
        HttpSession user = request.getSession();
        Administrador root = (Administrador)user.getAttribute("user");
        out.println(Utilities.getDocType());
        out.println("<HTML>" + Utilities.getHead("Eliminar proyectos"));
        out.println("<div id=\"container\">");
        out.println(Utilities.getIntro("Utilice esta vista para eliminar proyectos",root));

        String form = 
        	"<div id=\"pageContent\">"+
                        this.getForm() +
                        Utilities.getFooter() +
                "</div>";

        out.println(form);
        out.println(Utilities.getMenu());
        out.println("</div> <!-- fin container---></BODY></HTML>");
        out.close();
    }

    private String getForm() {
        ProjectManager pm = new ProjectManager();
        ArrayList<Proyecto> proyectos = pm.getProyectos();
        String tabla = "";

        for (Proyecto pr : proyectos) {
            tabla += "<tr>" +
                    "<td><input name=\"id\" value = \"" + pr.getId() + "\" type=\"checkbox\" size=\"20\"></td><td>" + pr.getNombre() + "</td>" +
                    "</tr>";
        }
        return "<form method = \"GET\">" +
					"<h3><span>Seleccione los proyectos a eliminar:</span></h3>" +
					"<p class=\"p1\"><span>" +
						"<Table border=\"1\" cellspacing=\"1\">" +
							"<tr>" +
								"<b><th>Id Proyecto</th><th>Nombre</th></b>" +
							"</tr>" + tabla +
						"</Table>" +
					"</span></p>" +
					"<p class=\"p1\"><span>" +
						"<input type=\"submit\" value=\"Eliminar\" name=\"Aceptar\">"+
						"<input type=\"reset\" value=\"Cancelar\" name=\"button2\">" +
					"</span></p>" +
					"</from>";
    }

    @Override
    public String getServletInfo() {
        return "Vista para eliminar proyecto.";
    }// </editor-fold>
}
